<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/17/017
 * Time: 11:56
 */

namespace app\index\controller;
use think\Controller;
class Login extends Controller
{
    public function login(){
        $username = input('username','','trim');
        $pass = input('password','','trim');
        if(empty($username) || empty($pass)){
            returnError('账号或密码为空');
        }else{
            $password=md5($pass);
            $jujian=db('jujian')->where('bh',$username)->where('bz',1)->where('passwd',$password)->find();
            if(empty($jujian)){
               returnError('用户名或密码错误');
            }
            //判断登录的账号是否是代理或者操作员
            $webName = true;
            if(substr($jujian['bh'],0,3) == 'CZY'){
                $par = db('jujian')->where('id',$jujian['par_id'])->find();
                if($par['lb_id'] == 1){
                    $is_show = true;
                }else{
                    $is_show  = false;
                }
            }else{
                if($jujian['lb_id'] == 1){
                    $webName = $jujian['bh'];
                    $is_show = true;
                }else{
                    $is_show  = false;
                }
            }
            if(!$webName){
                $webName = db('jujian')->where('id',$jujian['gt_jujian_id'])->value('bh');
            }
            $token =md5($jujian['id'] . time() . mt_rand(1,999)) . $jujian['id'];
            cache($jujian['id'],$token);
            //所有显示的货币
            $hb_array = db('huobi')->where('bz',1)->column('id');
            cache('hb_array',$hb_array);
            returnSuccess(['token'=>$token,'xingming'=>$jujian['xingming'],'bh'=>$jujian['bh'],'is_show'=>$is_show,'webName'=>$webName],'登陆成功');
        }
    }
}